/*
 *  AS IS License 
 * ==Naive Coders==
 */
package com.naivecoders.refex;

import java.util.HashMap;
import java.util.Map;

import com.naivecoders.refex.functions.AbstractFunction;
import com.naivecoders.refex.functions.FCode;
import com.naivecoders.refex.functions.InvocationException;

/**
 *
 * @author andrew
 */
public class Namespace {

    private final static FName ENTRY = new FName(FCode.A, FCode.A, FCode.A);
    private final Map<FName, AbstractFunction> functions = new HashMap<>();

    public void define(FName name, AbstractFunction fn) {
        functions.put(name, fn);
    }

    public AbstractFunction get(FName name) throws InvocationException {
        final AbstractFunction result =  functions.get(name);
        if (result == null ){
            throw new InvocationException("failed to resolve %s", name);
        }
        return result;
    }

    public AbstractFunction getEntry() throws InvocationException {
        return get(ENTRY);
    }
}
